"""
实现了WGS-84 -> GCJ-02 -> BD-09的转换
"""
import pandas as pd
import numpy as np
from gps_correction import gpschange as gps

def gps2baidu(file_in, file_out):
    reader = pd.DataFrame(pd.read_csv(file_in))
    X = np.array(reader[['latitude', 'longitude', 'weight']])
    a = []
    b = []
    c = []
    for i in range(len(X)):
        a1 = gps.wgs2gcj(X[i][0], X[i][1])
        a2 = gps.gcj2bd(a1[0], a1[1])
        a.append(a2[0])
        b.append(a2[1])
        c.append(X[i][2])
    c = pd.DataFrame({'latitude': a, 'longitude': b, 'weight': c})
    print(c)
    c.to_csv(file_out, index=0)

if __name__ == '__main__':
    time_ = [['00-00', '01-00'],
             ['01-00', '02-00'],
             ['02-00', '03-00'],
             ['03-00', '04-00'],
             ['04-00', '05-00'],
             ['05-00', '06-00'],
             ['06-00', '07-00'],
             ['07-00', '08-00'],
             ['08-00', '09-00'],
             ['09-00', '10-00'],
             ['10-00', '11-00'],
             ['11-00', '12-00'],
             ['12-00', '13-00'],
             ['13-00', '14-00'],
             ['14-00', '15-00'],
             ['15-00', '16-00'],
             ['16-00', '17-00'],
             ['17-00', '18-00'],
             ['18-00', '19-00'],
             ['19-00', '20-00'],
             ['20-00', '21-00'],
             ['21-00', '22-00'],
             ['22-00', '23-00'],
             ['23-00', '00-00']]
    for i in range(1, 8):
        for j in range(0, 24):
            file_in = '..\\data\\after_K-means\\week_' + str(i) + '\\time ' + time_[j][0] + '~' + time_[j][
                1] + '.csv'
            file_out = '..\\data\\final_data\\week_' + str(i) + '\\time ' + time_[j][0] + '~' + time_[j][
                1] + '.csv'
            gps2baidu(file_in, file_out)




